<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<!DOCTYPE HTML>
<html>
<head>
    <base href="${ctx }/">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <link rel="stylesheet" href="plugin/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="plugin/bootstrap-table/dist/bootstrap-table.css">
    <link rel="stylesheet" href="alert/alert.css">
     <style type="text/css">
         .addbr{
     float: right;
    margin-right: 80px;
  }
  .pad{
    padding-left:15px;
    padding-top:10px;
  }
  .im{
     padding:10px;
  }
  .padtr{
      margin-top:5px;
  }
  #filediv1{
  border: 2px solid #ccc6c6;
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    display: inline-block;
    margin-right: 20px;
  }
        a{
        color: #73879C;
        }
    </style>
</head>
<body>

    <div class="row base-margin" id="query">
            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="javascript:void(0)">Driver Management(司机管理)</a>
                </li>
                <li class="active">
                    <a href="view/driver/driver.jsp">Driver Database(司机列表)</a>
                </li>
            </ul>
        </div>
        <div>
            <div class="form-inline" role="form" method="post" id="queryForm">
                <div class="form-group">
                    <label>Registration Time(注册时间):</label>
                    <input type="text" class="form-control input-append form_date" id="createTime">-
                    <input type="text" class="form-control input-append form_date" id="loginTime">
                </div>
                <div class="form-group">
                    <label>Name(名称):</label>
                    <input type="text" id="name" class="form-control">
                </div>
                <div class="form-group">
                    <label>Phone(电话):</label>
                    <input type="text" id="telephone" class="form-control">
                </div>
                <!-- <div class="form-group">
                    <label>车牌号:</label>
                    <input type="text" id="email" class="form-control">
                </div> -->
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button id="queryBtn" onclick="doQuery1('demo-table',queryParams1())" class="btn btn-primary">Search(搜索)
                </button>
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 <button id="queryBtn" onclick="addDriver()" class="btn btn-primary">Add Driver(添加司机)
                </button>
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 <button id="queryBtn" onclick="exportTable()" class="btn btn-primary">Export(导出)
                </button>
            </div>
        </div>
         <input type='hidden' id="sortName" />
          <input type='hidden' id="order" />
         
    <div class="container" style="width: 100%;margin-top:15px">
        <table id="demo-table">
        </table>
    </div>

</body>

<!-- 加载需要的js -->
     <script src="js/jquery-3.2.1.min.js"></script>
	<script src="plugin/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	<script src="js/jquery-bootstrap-pagination.js"></script>
	<script src="plugin/bootstrap-table/dist/bootstrap-table.min.js"></script>
	<script src="plugin/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
	<!--时间  -->
	<script src="js/bootstrap-datetimepicker.js"></script>
	<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	<script src="js/common.js"></script>
	<script src="plugin/layer/layer.js"></script>
	<script src='alert/alert.js'></script>
	
<script type="text/javascript" charset="utf-8">
    var M = {}

    $('.form_date').datetimepicker({
        minView: "month", //选择日期后，不会再跳转去选择时分秒
        language: 'zh-CN',
        format: 'dd/mm/yyyy',
        todayBtn: 1,
        autoclose: 1,
    });

    function exportTable(){
    	var telephone = $('#telephone').val();
        var createTime= $('#createTime').val();
       var loginTime= $('#loginTime').val();
    	window.location.href="user/exportDriverList?telephone="+telephone+"&createTime="+createTime+"&loginTime="+loginTime;
    }
    
    $(function () {
        initPath("${ctx }");
      initDriverTable('demo-table', queryParams, columns, "user/drivers")
    });
 function initDriverTable(id,queryParams,columns,url){
	 $('#'+id+'').bootstrapTable({
	    	method:'GET',
	        dataType:'json',
	        contentType: "application/x-www-form-urlencoded",
	        cache: false,
	        striped: true,    
	        sortOrder:"asc",
	        //是否显示行间隔色
	        sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
	        url:url,
	        height: $(window).height() - 110,
	        width:$(window).width(),
	        /* showColumns:true, */
	        pagination:true,
	        queryParams : queryParams,
	        minimumCountColumns:2, 
	        pageNumber:1,                       //初始化加载第一页，默认第一页
	              pageSize:10,                       //每页的记录行数（*）
	              pageList: [5,10,15,25,50,100],        //可供选择的每页的行数（*）
	              uniqueId: "id",                     //每一行的唯一标识，一般为主键列
	        showExport: true,                    
	        exportDataType: 'all',
	        responseHandler: responseHandler,
	        columns: columns,
	        onSort:function(name, order){
	        	if(order=="asc"){
	        		$('#order').val("desc");
	        	}else{
	        		$('#order').val("asc");
	        	}
	        	$('#sortName').val(name);
	        }
	    });
 }
    var columns = [{field: '', title: 'Choose', checkbox: true},
        {
            field: 'picture',
            title: 'Head portrait(头像)',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return value == null ? "" : "<img src='" + value + "' style='width:60px;height:60px'/>";
            }
        },
        {
            field: 'firstName',
            title: 'Name(名称)',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'telephone',
            title: 'Phone(电话)',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
            	return "04"+value;
            }
        },
        {
            field: 'sex',
            title: 'Gender(性别)',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                if (value == 0) {
                    return "Male";
                } else if (value == 1) {
                    return "Female";
                } else {
                    return "Other";
                }
            }
        },
        {
            field: 'address',
            title: 'Address(地址)',
            align: 'center',
            valign: 'middle'
        }, 
        {
            field: 'carCount',
            title: 'Vehicle Numbers(车辆数量)',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'license_plate',
            title: 'REGO(车牌号)',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'mileage',
            title: 'Mileage(公里)',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'remark',
            title: 'Reviews(评分)',
            align: 'center',
            valign: 'middle',
            formatter:function(value, row, index){
            	var str="";
            	for(var i=0;i<value;i++){
            		str+="<img src='images/starOne.png' style='width:30px;height:30px;margin-left:5px'/>";
            	}
            	return str;
            },
            sortable:true
        },

        {
            field: 'create_time',
            title: 'Registration Time(注册时间)',
            align: 'center',
            valign: 'middle',
            formatter: timeStamp2String,
            sortable:true
        },
        {
            field: 'isOnline',
            title: 'online/ offline(是否在线)',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return value != null && value == 1 ? "online" : "offline";
            }
        },
        {
            field: 'isDeleted',
            title: 'Status(状态)',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return value != null && value == 1 ? "Banned" : "Active";
            }
        },
        {
            field: 'abn',
            title: 'ABN(ABN)',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'company',
            title: 'Company(公司)',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'licenceImg',
            title: 'Driver’s License(驾照)',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'id',
            title: 'Operation(操作)',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
            	sessionStorage.setItem("driver"+value, JSON.stringify(row));
                var str = '<a class="btn btn-info" style="margin-left:5px" href="user/driver/info?id='+row.id+'">Detail</a>';
                str += '<a class="btn btn-info" style="margin-left:5px;background-color: darkcyan;border-color: #76d8cf;" href="javascript:void();" onclick="addDriver('+row.id+')">Update</a>';
                str += '<a class="btn btn-info" style="margin-left:5px;background-color: darkcyan;border-color: #76d8cf;" href="javascript:void();" onclick="del('+row.id+')">Delete</a>';
               
                
                
                if(row.isDeleted == 0){
                    str += '<button class="btn btn-danger" style="margin-left:5px" onclick="changeStatus('+row.id+',1,this)">Disabled</button>';
                }else{
                    str += '<button class="btn btn-info" style="margin-left:5px" onclick="changeStatus('+row.id+',0,this)">Enabled</button>';
                }
                return str;
            }
        }
    ];
    function del(id){
    	var  flag =  confirm("Are you sure you want to delete?");				
    	  if(flag){
    			 $.ajax({
    		            type: "get",
    		            url: "user/deleteUser",
    		            dataType:"json",
    		            data:{"id":id},
    		            success: function(data){    
    		           	  console.log(data)
    		          	  if(data.code==200){	 
    		          		doQuery1('demo-table',queryParams1());
    			        	 }else{
    			        		  layer.msg(data.msg); 
    			        	 }
    		       }
    		        }); 
    	  }
    }
    function queryParams(params) {
        var param = {
            telephone: $('#telephone').val(),
            createTimes: $('#createTime').val(),
            loginTimes: $('#loginTime').val(),
            name: $('#name').val(),
            email: $('#email').val(),
            order:$('#order').val(),
            sortname:$('#sortName').val(),   
            pageNo: this.pageNumber,
            pageSize: this.pageSize
        }
        return param;
    }

    function queryParams1() {
        var param = {
            telephone: $('#telephone').val(),
            createTimes: $('#createTime').val(),
            loginTimes: $('#loginTime').val(),
            name: $('#name').val(),
            email: $('#email').val(),
            pageNo: 1,
            pageSize: this.pageSize
        }
        return param;
    }
    
//添加司机
    function addDriver(id){
	var title="Add Driver";var firstName="";var middleName="";var name="";
	var birthday="";var sex="";var telephone="";var cityId="";var email="";
	var address="";var remark="";var postcode="";var company="";var ids="";
	if(id!=undefined){
		var row=JSON.parse(sessionStorage.getItem("driver"+id));
		title="Update Driver";
		firstName=row.firstName==null?"":row.firstName;
		middleName=row.middleName==null?"":row.middleName;
		name=row.name==null?"":row.name;
		birthday=row.birthday==null?"":row.birthday;
		telephone=row.telephone==null?"":row.telephone;
		email=row.email==null?"":row.email;
		address=row.address==null?"":row.address;
		postcode=row.postcode==null?"":row.postcode;
		company=row.company==null?"":row.company;
		remark=row.remark==null?"":row.remark;
		cityId=row.cityId==null?"":row.cityId;
		ids=row.id;
	}
     			layer.open({
     	 			  type: 1,
     	 			  title: title,
     	 			  skin: 'layui-layer-rim', //加上边框
     	 			  area: ['620px', '660px'], //宽高
     	 			  content: ' <form id="adds" id="adds"><table>'+
     	 			  '  <tr class="padtr"><td class="pad">Upload the picture(上传头像):</td> '+
     	 			 ' <td style="padding: 10px 20px;"><div id="filedivs1" ><label for="file1" ><div id="filediv1" ><span class="glyphicon glyphicon-plus im"></span></div>'+
     		        '<input type="file" id="file1"  onchange="fileSize(this,1)" accept="image/jpeg,image/jpg,image/png" style="display:none"/>  </label></div>'+
     		        '<input type="hidden" id="result1" /><img src="" style="width:50px;height:50px;display:none" onclick="javascript:$(\'#file1\').click()" id="imgs1"/>'+
     		        '</td></tr>'+     	 		      
                    '<tr><td><span style="font-size:20px">Driver Information(司机信息)：</span></td></tr>'+
     	 			  '  <tr class="padtr"><td class="pad">Name(名称):</td> '+
     	        '<td><input type="hidden" name="id" value="'+ids+'"/><input type="text"  style="width:80px" name="firstName" id="firstName" value="'+firstName+'">&nbsp;<input type="text" style="width:80px" id="middleName"   name="middleName">&nbsp;<input type="text" style="width:80px" id="name"value="'+name+'" name="name"></td></tr>'+
     	        '  <tr class="padtr"><td class="pad">Date of birth(生日):</td> '+
     	        '<td><input type="text" class="form-control  input-append form_date" name="birthday" id="birthday"/></td></tr>'+
     	       '  <tr class="padtr"><td class="pad">Gender(性别):</td> '+
    	        '<td><select class="form-control" name="sex" id="sex"><option value="0">male<option><option value="1">female<option><option value="2">Other<option></select></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">Phone(电话):</td> '+
     	        '<td><input type="text" class="form-control" id="telephone"  value="'+telephone+'" name="telephone" id="telephone1" oninput="regTel(\'telephone1\')" /></td></tr>'+
     	       '  <tr class="padtr"><td class="pad">City(城市):</td> '+
   	        '<td><select id="cityId" name="cityId"></select></td></tr>'+
     	       '  <tr class="padtr"><td class="pad">Email(邮箱):</td> '+
    	        '<td><input type="text" class="form-control" name="email" id="email" value="'+email+'"  oninput="regEmail(\'email\')" /></td></tr>'+
     	       '  <tr class="padtr"><td class="pad">Address(地址):</td> '+
    	        '<td><input type="text" class="form-control" name="address" /></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">Postcode(邮编):</td> '+
    	        '<td><input name="postcode" type="text" class="form-control"  value="'+postcode+'"/></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">ABN(ABN):</td> '+
    	        '<td><input type="text" class="form-control" name="abn" /></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">Company Name(公司名称):</td> '+
    	        '<td><input type="text" class="form-control" name="company" value="'+company+'"/></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">Ratings(评分):</td> '+
    	        '<td><img style="width:80px" src="images/star.png"/></td><td><input type="number" valeu="'+remark+'" oninput="regremark(\'remark\')" class="form-control" name="remark"  id="remark" style="width:80px; margin-left: -152px;"  oninput="reg(\'remark\')"/></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">Driver’s License(驾照):</td> '+
    	        '<td><input type="file" id="file3" onchange="fileSize1(this,3)" /><input type="hidden" id="result3" name="licenceImg"/></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">Drivers Accreditation(司机认证):</td> '+
    	        '<td><input type="file" id="file2" onchange="fileSize1(this,2)"/><input type="hidden" id="result2" name="driverAccreditation"/></td></tr>'+
    	        '  <tr class="padtr"><td class="pad">Hire Car License(汽车执照):</td> '+
    	        '<td><input type="file" id="file4" onchange="fileSize1(this,4)"/><input type="hidden" id="result4" name="hireCarLicense"/></td></tr>'+
    	        '<tr align="center" class="padtr" ><td colspan="5" style="padding-top:10px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
     	        ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
     	        ' <button type="button" onclick="cacel()" class="btn btn-info btn1">&nbsp;&nbsp;Cancel&nbsp;&nbsp;</button>'+
     	        '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
     	        '<button type="button" onclick="save()" class="btn btn-info btn1">&nbsp;&nbsp;Save&nbsp;&nbsp;</button></td></tr></table></form>'
     	 			});
     			initCity();
     		   $('.form_date').datetimepicker({
     		        minView: "month", //选择日期后，不会再跳转去选择时分秒 
     		        language: 'zh-CN',
     		        format: 'dd/mm/yyyy',
     		        todayBtn:  1,
     		        autoclose: 1,
     		    });
     		   $('#birthday').datetimepicker
     		   if(cityId!=""){
     			   $('#cityId').val(cityId);
     		   }
    }
    function initCity(){
    	 $.ajax({
   		  url:"user/getCity",
   		  type:"get",
   		  async:false,
         success: function(data){    
           	  if(data.code==200){
           		 $('#cityId').append("<option value=''>Please select a</option>");
                 for (var i in data.data) {
                     $('#cityId').append("<option value='" + data.data[i].id + "'>" + data.data[i].cityName + "</option>");
                 }
           	  }else{
           		  layer.msg(data.msg);
           	  }
             }
   	  });
    }
    function regremark(id){
    	var text=$('#'+id+'').val();
    	if(text<0||text>5){
    		 $('#'+id+'').css("border-color","#FF0000");
    		 $('#'+id+'').val('');
    	}else{
    		$('#'+id+'').css("border-color","#ccc")
    	}
    }
    function regEmail(id){
    	//var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    	var myreg =/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    	var text=$('#'+id+'').val();
    	if(!myreg.test(text)){
    		 $('#'+id+'').css("border-color","#FF0000")
    	}else{
    		$('#'+id+'').css("border-color","#ccc")
    	}
    }
  //点击div时点击file
    function fileSize1(obj,num){
          console.log(obj.files[0])
    	var formdata = new FormData();
        formdata.append("file", obj.files[0]);
        var xhr = new XMLHttpRequest();
        var index;
        xhr.upload.addEventListener("progress", function(e) {
        	 index = layer.load();
          //console.log('e.loaded=' + e.loaded + 'e.total=' + e.total);
          console.log(e)
        }, false);
        // 完成
        xhr.addEventListener("load", function(e) {
          console.log(xhr.responseText) //返回信息
          if(xhr.responseText!=""){
        	  layer.close(index);
      		var response=JSON.parse(xhr.responseText);
      	    $('#result'+num+'').val(response.data);
      	}
        }, false);
        // 错误
        xhr.addEventListener("error", function(e) {
        	 layer.close(index);
          // self.onFailure(file, xhr.responseText);
        }, false);
        xhr.open("POST", 'http://54.66.146.242:8080/fab_api/pcphoto/pcphotoImg', true);
        xhr.setRequestHeader("X_FILENAME", 'src');
        xhr.send(formdata);
    }
  
    function regTel(id){
    	var text=$('#'+id+'').val();
    	text=text.replace(/\s+/g,"");
    	if(text.length>10||text.length<8){
    		 $('#'+id+'').css("border-color","#FF0000")
    	}else{
    		$('#'+id+'').css("border-color","#ccc")
    	}
    }
    
    function reg(id){
    	var text=$('#'+id+'').val();
		 if(parseInt(text)<=0){
			 $('#'+id+'').css("border-color","#FF0000")
 		 }else{
 			$('#'+id+'').css("border-color","#ccc")
 		 }
    }
    
  //点击div时点击file
	function fileSize(file,num){
		 var image = new Image();
		 var _URL = window.URL || window.webkitURL;
		 var width =0; var height = 0;
	      image.onload =function(){  
	         width = image.width;  
	         height = image.height;
	         $('#filedivs'+num+'').css("display","none");
		      $('#imgs'+num+'').css("display","block");
		      $('#imgs'+num+'').attr("src",image.src);
	      }  
	    	  image.src =  _URL.createObjectURL(file.files[0]);
			    var reader = new FileReader();  
			    //将文件以Data URL形式读入页面  
			    reader.readAsDataURL(file.files[0]);  
			    reader.onload=function(e){  
			    	var r = "result"+num+"";
			        var result=document.getElementById(r);  
			        //显示文件  
			        result.value=this.result;  
	      }
	}
  //添加司机
  function save(){
	  
	 var forms= serialize('adds');
	 if(forms.firstName==null||forms.firstName==""){
 		layer.msg("firstName cannot be empty");
 		return;
 	}
 	  
 	var bir=forms.birthday.split('/');
 	forms.birthday=bir[2]+"-"+bir[1]+"-"+bir[0];
 	if(forms.telephone==null||forms.telephone==""){
 		layer.msg("Phone number cannot be empty");
 		return;
 	}
 	if(forms.email==null||forms.email==""){
 		layer.msg("Email cannot be empty ");
 		return;
 	}
 	var telephone=forms.telephone;
 	forms.telephone=telephone.replace(/\s+/g,"");
	if(forms.telephone.length>11||forms.telephone.length<8){
		layer.msg("The telephone number can only be 10 bits long.");
 		return;
	}
 	if(forms.remark==null||forms.remark==""||forms.remark>5){
 		layer.msg("The score should not be empty and the score should not be greater than 5.");
 		return;
 	}
 	if(forms.cityId==null||forms.cityId==""){
 		layer.msg("City  cannot be empty");
 		return;
 	}
 	var result1=$('#result1').val();
 	var telephone=forms.telephone;
 	forms.telephone =telephone.substring(telephone.length-8, telephone.length); 
 	//添加用户时判断
 	  if(forms.id==""){
 		  if(forms.licenceImg==""){
 		 		layer.msg("A driver's license cannot be empty.");
 		 		return;
 		 	}  
 		 	if(forms.hireCarLicense==null||forms.hireCarLicense==""){
 		 		layer.msg("Hire Car License  cannot be empty");
 		 		return;
 		 	} 
 		 	if(result1==""){
 		 		layer.msg("Head portrait cannot be empty");
 		 		return;
 		 	}  
 		 	if(forms.birthday==null||forms.birthday==""){
 		 		layer.msg("Birthday cannot be empty");
 		 		return;
 		 	}  
 			if(forms.driverAccreditation==null||forms.driverAccreditation==""){
 		 		layer.msg("driver Accreditation cannot be empty");
 		 		return;
 		 	}  
 		 	
 	  }else{
 		 if(forms.licenceImg==null||forms.licenceImg==""){
 			forms.licenceImg=null;
		 	}  
 		if(forms.hireCarLicense==null||forms.hireCarLicense==""){
 			forms.hireCarLicense=null;
		 	} 
 		if(result1==""){
 			result1=null;
		 	} 
 		if(forms.birthday==null||forms.birthday==""){
 			forms.birthday==null;
 	 	}  
 		if(forms.driverAccreditation==null||forms.driverAccreditation==""){
 			forms.driverAccreditation==null;
		 	}  
 	  }
 	if(forms.abn==null&&forms.abn==""){
 		layer.msg("ABN cannot be empty");
 		return;
 	}
 	if(forms.company==null&&forms.company==""){
 		layer.msg("Company cannot be empty");
 		return;
 	}
 forms.picture =result1;
 layer.load(1, {shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	  $.ajax({
		  url:"user/addDrivers",
		  type:"post",
		  data: JSON.stringify(forms),
          contentType:"application/json;charset=UTF-8", 
          dataType:"json",
          success: function(data){    
        	  if(data.code==200){
        		  layer.closeAll();
        		  $('#demo-table').bootstrapTable('refreshOptions',queryParams());
        	  }else{
        		  layer.msg(data.msg);
        	  }
          }
	  });
  }
  
  
    function changeStatus(id,isDeleted,current) {
        $.post(
            "user/update",
            {id:id,isDeleted:isDeleted},
            function (json) {
            	var str="";var str1="";
            	if(isDeleted==0){//启用
            		str="Unlock success";
            		str1="Unlock failure";
            	}else{
            		str="Titles success";
            		str1="Titles failure";
            	}
                if(json.code == 200){
                    M.dialog2 = jqueryAlert({
                        'title': 'Notification',
                        'content': '<p>'+str+'</p>',
                        'width': "320",
                        'modal': true,
                        'buttons': {
                            'OK': function () {
                                M.dialog2.close();
                                $('#demo-table').bootstrapTable('refreshOptions',queryParams());
                            }
                        }
                    });
                    if(isDeleted == 0){
                        $(current).attr("class","btn btn-danger");
                        $(current).attr("onclick","changeStatus("+id+",1,this)");
                        $(current).parent().prev().text("Enabled");
                        $(current).text("Disabled");
                    }else{
                        $(current).attr("class","btn btn-info");
                        $(current).attr("onclick","changeStatus("+id+",0,this)");
                        $(current).parent().prev().text("Disabled");
                        $(current).text("Enabled");
                    }
                }else{
                    M.dialog2 = jqueryAlert({
                        'title': 'Notification',
                        'content': '<p>'+str1+'</p>',
                        'width': "320",
                        'modal': true,
                        'buttons': {
                            'OK': function () {
                                M.dialog2.close();
                                $('#demo-table').bootstrapTable('refreshOptions',queryParams());
                            }
                        }
                    });
                }
                if (M.dialog2) {
                    return M.dialog2.show();
                }
            }
        )
    }
</script>
</html>


